home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / magazine / c_news / 16 / sets / setsourc / sets.h < prev    next >
Text File  |  1989-02-26  |  5KB  |  119 lines

  1. /* sets.h  --  Header file for implementation of data type, set, in C
  2.  
  3.                 by Arnold S. Cherdak, February 26, 1989.
  4.                 First implementation for Turbo-C, Version 2.0
  5.  
  6.      DISCLAIMER - DISCLAIMER - DISCLAIMER - DISCLAIMER - DISCLAIMER
  7.       Use at your own risk, The author is NOT responsible for ANY
  8.      damages resulting from the use, proper or improper, of this
  9.      software.
  10.  
  11.       References for this implementation were:
  12.  
  13.                 Cooper, Doug, STANDARD PASCAL, USER REFERENCE MANUAL,
  14.                 1983, W.W. Norton & Co., New York.
  15.  
  16.                 Koffman, E. B., PROBLEM SOLVING AND STRUCTURED PROGRAMMING
  17.                 IN PASCAL, Second Ed., 1985, Addison-Wesley, Reading, Mass.
  18.  
  19.                 The Institute of Electrical and Electronics Engineers, Inc.,
  20.                 AN AMERICAN NATIONAL STANDARD, IEEE STANDARD PASCAL COMPUTER
  21.                 PROGRAMMING LANGUAGE (ANSI/IEEE 770X3.97-1983), 1983, Wiley.
  22.  
  23.                 Kernighan, Brian W., and Ritchie, Dennis M., THE C PROGRAMMING
  24.                 LANGUAGE, 1978, Prentice-Hall, Englewood Cliffs, NJ.
  25.  
  26.                 Schwaderer, W. David, C WIZARD'S PROGRAMMING REFERENCE, 1985,
  27.                 Wiley.
  28.  
  29. */
  30. #define BITS_PER_INTEGER 16  /* for MS-DOS systems on 8/16-bit machines */
  31.                              /* Use function wordlength() to find out. */
  32.  
  33. #define  MEMBERS_PER_WORD  BITS_PER_INTEGER
  34. #define  MAX_MEMBERS 256     /* This parameter is an upper limit that can */
  35.                               /* be changed as desired.  It's a compromise */
  36.                               /* to save space.  Can be up to 32K for a    */
  37.                               /* 16-bit integer size.                      */
  38.  
  39. #define NOCHANGE (2)
  40. #define SUCCESS (1)
  41. #define FAILURE (0)
  42. #define _E    -2             /* END_OF_LIST; used to terminate input list */
  43.                              /* of set members */
  44.  
  45. #define __ ,-1,              /* 'thru, __ ' used to denote contiguous */
  46.                              /*  set members as in 'A'__'B'. i.e. double */
  47.                              /*  underscore rather than two dots, ".." */
  48.  
  49. typedef enum {FALSE=0, TRUE=1} boolean;   /* needed for return values */
  50.  
  51. /* These are all the ordinal types permitted to be set base types.  All
  52.     these are predefined in Pascal.  The subrange type is as defined in Pascal
  53.     and consists of a contiguous range of integer values.  Character and
  54.     Boolean are predefined types having 256 and 2 members, respectively, in
  55.     MS-DOS implementations.  Enum and Subrange are type classes that can have
  56.     numerous types.  However, ANSI C doesn't do type checking of ENUM types.
  57.     These were left to the user to be careful about how they are used.
  58.  
  59.     Note that type UNIVERSAL is not intended for the user but, rather, for
  60.     internal use as may be seen in the functions for intersection, difference,
  61.     etc.  It might be useful, however, in debugging since type checking of
  62.     base_type, UNIVERSAL, sets is suspended.
  63.  
  64.     Note also that base_type, SUBRANGE, stands in for integer and enumerated
  65.     types.  Enumerated type set applications are straightforward and need
  66.     little, if any, explanation, especially to Pascal programmers.  The
  67.     application to integer subranges, though, deserves a word.  All set
  68.     members are numbered from 0..nmembers.  As a result, an integer subrange
  69.     that lies fully or partially outside this range may result in an error
  70.     message or, worse, improper operation.  It would be a good thing to keep
  71.     integer subranges within the nmember limit or convert them to an enumerated
  72.     type by placing a letter before the number.  i.e., X300..X310.  Another
  73.     option would be to expand MAX_MEMBERS to include the subrange.
  74.  
  75. */
  76. typedef enum {UNIVERSAL, BOOLEAN, CHARACTER, ENUMERATED, SUBRANGE} base;
  77.  
  78. /* The following structure IS a set */
  79. typedef struct SET {
  80.     base base_type;
  81.     int set_size;
  82.     int nmembers;
  83.     int member_recs;
  84.     int set_tag;
  85.     unsigned word[MAX_MEMBERS / MEMBERS_PER_WORD];
  86. } set;
  87.  
  88. /* This macro provides a set declaration and should be used whenever a
  89.    set object must be declared.
  90. */
  91. #define defset(set_name,bastyp,size,tag) struct SET set_name\
  92.  = {bastyp,size,0,((size/MEMBERS_PER_WORD)+(size%MEMBERS_PER_WORD?1:0)),tag}
  93.  
  94. /* FUNCTION PROTOTYPES FOR SET FUNCTIONS */
  95. void dump_set(set *aset);
  96. void set_print(set *aset);
  97. unsigned wordlength(void);
  98. int add_member(set *aset, int member);
  99. int del_member(set *aset, int member);
  100. boolean in_set(set *aset, int entity);
  101. int set_assign(set *destination, set *source);
  102. void set_clear(set *aset);
  103. int check_set_types(set *set1, set *set2);
  104. int set_intersect(set *intersect, set *set1, set *set2);
  105. int set_union(set *xunion, set *set1, set *set2);
  106. int set_difference(set *difference, set *minuend, set *subtrahend);
  107. int set_member_count(set *aset);
  108. boolean set_equality(set *left, set *right);
  109. boolean set_inequality(set *left, set *right);
  110. boolean set_included_in(set *left, set *right);
  111. boolean set_includes(set *left, set *right);
  112. boolean cmp_base_types(set *seta,set *setb);
  113. boolean cmp_set_tags(set *seta,set *setb);
  114. int set_of(set *aset,...);
  115. int set_args(set *aset, va_list ap);
  116.  
  117. /* END set.h */
  118.  
  119.